package com.chzc.fm.duotin.ui.more;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chzc.fm.duotin.R;

import java.util.List;

/**
 * Created by hasee on 2016/7/1.
 */
public class MyRecommendAdapter extends RecyclerView.Adapter<MyRecommendAdapter.MViewHolder>{
    private Context context;
    private List<Recommend_Application> listdata;
    private LayoutInflater inflater;
    public MyRecommendAdapter(Context context,List<Recommend_Application>appdata){
        super();
        this.context=context;
        this.listdata=appdata;

        inflater = LayoutInflater.from(context);
    }
    public int getItemCount(){
        return listdata.size();
    }
    public MViewHolder onCreateViewHolder(ViewGroup viewGroup,int arg1){
        View view=inflater.inflate(R.layout.item_home,null);
        return new MViewHolder(view);
    }
    public void onBindViewHolder(MViewHolder mViewHolder,int arg1){
        mViewHolder.mtextView.setText(listdata.get(arg1).getTextView1());
        mViewHolder.HtextView.setText(listdata.get(arg1).getTextView2());
        mViewHolder.image2.setBackgroundResource(listdata.get(arg1).getImageleft());
        mViewHolder.image1.setBackgroundResource(listdata.get(arg1).getImageright());
//        mViewHolder.recommend_item_linner.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                LayoutInflater inflater=LayoutInflater.from(context);
//                View v=inflater.inflate(R.layout.recommend_dialog,null);
//                final Dialog dialog=new Dialog(context,R.style.dialog);
//                dialog.setContentView(v);
//                Window dialogwindow=dialog.getWindow();
//                final Window dialogWindow = dialog.getWindow();
//                WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//                dialogWindow.setGravity(Gravity.CENTER_VERTICAL |Gravity.CENTER_HORIZONTAL);
//                lp.x =0; // 新位置X坐标
//                lp.y =0; // 新位置Y坐标
//                lp.width = 450; // 宽度
//                dialogWindow.setBackgroundDrawable(new BitmapDrawable());
//                dialogWindow.setAttributes(lp);
//                //点击弹出框外围退出
//                dialog.setCanceledOnTouchOutside(true);
//                dialog.setCancelable(true);
//
//                dialog.show();
//                 Button recommendApp_yes,recommendApp_no;
//                recommendApp_yes=(Button)view.findViewById(R.id.recommendApp_yes);
//                recommendApp_no=(Button)view.findViewById(R.id.recommendApp_no);
//                recommendApp_yes=(Button)v.findViewById(R.id.clean);
//                recommendApp_no=(Button)v.findViewById(R.id.unclean);
//                recommendApp_yes.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        dialog.dismiss();
//                    }
//                });
//                recommendApp_no.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        dialog.dismiss();
//                    }
//                });
//
//            }
//        });

    }


    public class MViewHolder extends  RecyclerView.ViewHolder{
        public TextView mtextView;
        public TextView HtextView;
        public ImageView image1;
        public ImageView image2;

        private LinearLayout recommend_item_linner;
        public MViewHolder(View view){
            super(view);
            this.mtextView=(TextView)view.findViewById(R.id.item_text1);
            this.HtextView=(TextView)view.findViewById(R.id.item_text2);
            this.image1=(ImageView)view.findViewById(R.id.item_image1);
            this.image2=(ImageView)view.findViewById(R.id.item_image2);
            recommend_item_linner=(LinearLayout)view.findViewById(R.id.recommendApp_line);

        }
    }
}
